<?php

namespace Seguridad\Controller;

use Seguridad\Controller\GenericController;
use Componentes\Controller\UtilsArrayController;

class GrupoController extends GenericController {

    public function __construct() {
        
    }

    public function get($id) {
        // obtener el id del registro a obtener
        $id = $this->params()->fromRoute('id');
        $output = $this->getGrupoService()->getRegistro($id);
        return $this->convertirArrayAJson($output);
    }

    /**
     * Return list of resources
     * @return mixed
     */
    public function getList($id = 1, $param1 = 1, $param2 = 1, $param3 = 1) {
        $id = $this->params()->fromRoute('id');
        $param1 = $this->params()->fromRoute('param1');
        $data = null;
        $mensaje = "Defaul";

        switch ($id) {
            case (1):
                /*
                 * Datos del grupo dado el login
                 * Ej: http://localhost/UptaebBackend/public/seguridad/grupo/1/07443224
                 */
                $login = $this->params()->fromRoute('param1');
                $registros = $this->getGrupoService()->getGrupoSegunLogin($login);
                $data = UtilsArrayController::llenarData($registros);
                $output = UtilsArrayController::organizarOutput(true, $data, null);
                break;
            case (2):
                $login = $this->params()->fromRoute('param1');
                $password = $this->params()->fromRoute('param2');
                $output = $this->getGrupoService()->validarGrupo($login, $password);

                break;
            default:
                return $param1;
        }
        return $this->convertirArrayAJson($output);
    }

    /**
     * Delete an existing resource
     * @param  mixed $id
     * @return mixed
     */
//    public function delete($id) {
//        // obtener el id del registro
//        $id = $this->params()->fromRoute('id');
//        // Eliminar el registro
//        //$alumno_service = new \Seguridad\Controller\Service\AlumnoService($this->getServiceLocator()->get('db'));
//        $grupo_service = Service\GrupoService::getInstance();
//        $result = $grupo_service->deleteRegistro($id);
//        $response = $this->getResponseWithHeader();
//        $response->setContent($result);
//        return $response;
//    }

    /**
     * Update an existing resource
     * @param  mixed $id
     * @param  mixed $data
     * @return mixed
     */
//    public function updateAction() {
//        $id = $this->params()->fromRoute('id');
//        $estado = $data = (string) $this->params()->fromRoute('id2');
//        $turno = $data = (string) $this->params()->fromRoute('id3');
//        $data = array('salumestado' => $estado, 'turno' => $turno);
//        $result = $this->getGrupoService()->updateRegistro($id, $data);
//        $response = $this->getResponseWithHeader();
//        $response->setContent($result);
//        return $response;
//    }

    /**
     * Create a new resource
     * @param  mixed $data
     * @return mixed
     */
//    public function create($data) {
//        $data = $this->params()->fromPost();
//        // Guardar el registro
//        $grupo_service = new Service\GrupoService($this->getServiceLocator()->get('Zend\Db\Adapter'));
//        $result = $grupo_service->createRegistro($data);
//        $response = $this->getResponseWithHeader();
//        $response->setContent($result);
//        return $response;
//    }
}
